package com.ld.security.auth.common.base.aop;

import com.ld.security.auth.common.util.AuthUtil;
import com.ld.security.common.core.base.po.QueryPo;
import com.ld.security.common.core.base.po.SuperPo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.LinkedList;

/**
 * 查询预处理
 * 为对象添加额外参数
 */
@Component
@Aspect
@Order(10)
public class QueryMappingAop {


    @Pointcut("@annotation(com.ld.security.common.core.anno.QueryMapping)")
    public void aop() {

    }


    public void queryBefore(SuperPo entity){
       // AuthUtil.initEntity(entity);

    }



   @Around("aop()")
    public Object doAroundAdvice(ProceedingJoinPoint pjp) throws Throwable{
       LinkedList<SuperPo> list =   new LinkedList<>();

        for (Object o : pjp.getArgs()) {
           if(o instanceof QueryPo){
               QueryPo po = (QueryPo)o;
               SuperPo e = (SuperPo)po.getQuery();
                list.add(e);
           }else{
               list.add((SuperPo)o);
           }
       }

       for (SuperPo superPo : list) {
           queryBefore(superPo);
       }


        return pjp.proceed();
    }



}
